<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">






  
  
  <link rel="stylesheet" media="all" href="/blog/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="数据结构,读书笔记," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="堆的定义一棵完全二叉树：1, 若存在左孩子，则根结点的值小于左孩子；  若存在右孩子，则根结点的值小于右孩子； 左右子树又各是一个堆。堆具有新增、删除、输出数据3个功能堆的存储结构由堆的定义知，堆是一棵以k1为根的完全二叉树。若对该二叉树的结点进行编号(从上到下，从左到右)，得到的序列就是将二叉树的结点以顺序结构存放，堆的结构正好和该序列结构完全一致在这样的结构下，给定某节点的下标，A[i]可以用">
<meta name="keywords" content="数据结构,读书笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="堆">
<meta property="og:url" content="https://git.oschina.net/choichumgming/blog/2017/12/26/堆/index.html">
<meta property="og:site_name" content="choichumgming&#39;s blog">
<meta property="og:description" content="堆的定义一棵完全二叉树：1, 若存在左孩子，则根结点的值小于左孩子；  若存在右孩子，则根结点的值小于右孩子； 左右子树又各是一个堆。堆具有新增、删除、输出数据3个功能堆的存储结构由堆的定义知，堆是一棵以k1为根的完全二叉树。若对该二叉树的结点进行编号(从上到下，从左到右)，得到的序列就是将二叉树的结点以顺序结构存放，堆的结构正好和该序列结构完全一致在这样的结构下，给定某节点的下标，A[i]可以用">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://note.youdao.com/yws/res/1037/WEBRESOURCE7f2868a0fa33472ab0b6db0cf68009ee">
<meta property="og:updated_time" content="2017-12-26T10:12:25.931Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="堆">
<meta name="twitter:description" content="堆的定义一棵完全二叉树：1, 若存在左孩子，则根结点的值小于左孩子；  若存在右孩子，则根结点的值小于右孩子； 左右子树又各是一个堆。堆具有新增、删除、输出数据3个功能堆的存储结构由堆的定义知，堆是一棵以k1为根的完全二叉树。若对该二叉树的结点进行编号(从上到下，从左到右)，得到的序列就是将二叉树的结点以顺序结构存放，堆的结构正好和该序列结构完全一致在这样的结构下，给定某节点的下标，A[i]可以用">
<meta name="twitter:image" content="http://note.youdao.com/yws/res/1037/WEBRESOURCE7f2868a0fa33472ab0b6db0cf68009ee">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://git.oschina.net/choichumgming/blog/2017/12/26/堆/"/>





  <title>堆 | choichumgming's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">choichumgming's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">stay foolish,stay hard</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/blog/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      
        
        <li class="menu-item menu-item-board">
          <a href="/blog/board/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://git.oschina.net/choichumgming/blog/blog/2017/12/26/堆/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="choichumgming">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="choichumgming's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">堆</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-26T15:30:10+08:00">
                2017-12-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/算法与数据结构/" itemprop="url" rel="index">
                    <span itemprop="name">算法与数据结构</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/blog/2017/12/26/堆/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2017/12/26/堆/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <h2 id="堆的定义"><a href="#堆的定义" class="headerlink" title="堆的定义"></a>堆的定义</h2><p><strong>一棵完全二叉树：</strong><br>1, 若存在左孩子，则根结点的值小于左孩子；</p>
<ol>
<li>若存在右孩子，则根结点的值小于右孩子；</li>
<li>左右子树又各是一个堆。<br>堆具有新增、删除、输出数据3个功能<h3 id="堆的存储结构"><a href="#堆的存储结构" class="headerlink" title="堆的存储结构"></a>堆的存储结构</h3>由堆的定义知，堆是一棵以k1为根的完全二叉树。若对该二叉树的结点进行编号(从上到下，从左到右)，得到的序列就是将二叉树的结点以顺序结构存放，堆的结构正好和该序列结构完全一致<br><img src="http://note.youdao.com/yws/res/1037/WEBRESOURCE7f2868a0fa33472ab0b6db0cf68009ee" alt="enter image description here"><br>在这样的结构下，给定某节点的下标，A[i]<br>可以用<strong>变长数组</strong>来储存数据<h3 id="堆（Heap）的插入"><a href="#堆（Heap）的插入" class="headerlink" title="堆（Heap）的插入"></a>堆（Heap）的插入</h3>在<strong>最后插入</strong>，然后使用<strong>向上调整</strong>，使用<strong>递归向上调整</strong><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//向上调整代码</span></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">Insert</span><span class="params">(<span class="keyword">int</span> key)</span></span>&#123;</div><div class="line">        length++;</div><div class="line">        <span class="keyword">if</span>(length==<span class="number">1</span>)A[<span class="number">1</span>]=key;</div><div class="line">        <span class="keyword">else</span></div><div class="line">        &#123;</div><div class="line">            A[length]=key;</div><div class="line">            FilterUp(length);</div><div class="line">        &#125;</div><div class="line">    &#125;   </div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">FilterUp</span><span class="params">(<span class="keyword">int</span> index)</span></span>&#123;</div><div class="line">        <span class="keyword">if</span>(index ==<span class="number">1</span>)<span class="keyword">return</span> ;</div><div class="line">        <span class="keyword">int</span> parent=index/<span class="number">2</span>;</div><div class="line">        <span class="keyword">if</span>(A[index]&lt;A[parent])</div><div class="line">        &#123;</div><div class="line">            <span class="keyword">int</span> t=A[index]; A[index]=A[parent];A[parent]=t;</div><div class="line">            FilterUp(parent);</div><div class="line">        &#125;</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="堆（Heap）的删除"><a href="#堆（Heap）的删除" class="headerlink" title="堆（Heap）的删除"></a>堆（Heap）的删除</h3><p>Heap的删除则将完全二叉树的最后一节点取代被删除的节点，<br>  然后判断是否为一棵Heap，若不是，则再依照上述方法进行调整。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//完整代码</span></div><div class="line"><span class="keyword">package</span> Heap;</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyHeap1</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> A[];</div><div class="line">    <span class="keyword">int</span> length;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="title">MyHeap1</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">int</span> []B=<span class="keyword">new</span> <span class="keyword">int</span> []&#123;-<span class="number">1</span>,<span class="number">81</span>,<span class="number">49</span>,<span class="number">19</span>,<span class="number">38</span>,<span class="number">97</span>,<span class="number">76</span>,<span class="number">13</span>,<span class="number">19</span>,-<span class="number">2</span>,-<span class="number">2</span>,-<span class="number">2</span>,-<span class="number">2</span>&#125;; length=<span class="number">0</span>;<span class="comment">//如果不想写死大小，就用arralist</span></div><div class="line">        A=<span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">100</span>];</div><div class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> b:B)</div><div class="line">        &#123;</div><div class="line">            Insert(b);</div><div class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=length;i++)System.out.print(A[i]+<span class="string">" "</span>);</div><div class="line">            System.out.println();</div><div class="line">        &#125;</div><div class="line"><span class="comment">//      Insert(20);</span></div><div class="line"><span class="comment">//      for(int a:A)System.out.print(a+" ");System.out.println();</span></div><div class="line">        </div><div class="line"><span class="comment">//      for(int i=length;i&gt;1;i--)</span></div><div class="line"><span class="comment">//      &#123;</span></div><div class="line"><span class="comment">//          int t=A[1]; A[1]=A[i]; A[i]=t;</span></div><div class="line"><span class="comment">//          length--;</span></div><div class="line"><span class="comment">//          FilterDown(1);</span></div><div class="line"><span class="comment">//          for(int a:A)System.out.print(a+" ");System.out.println();</span></div><div class="line"><span class="comment">//      &#125;</span></div><div class="line">    &#125;</div><div class="line">    </div><div class="line">    <span class="function"><span class="keyword">void</span> <span class="title">Insert</span><span class="params">(<span class="keyword">int</span> key)</span></span>&#123;</div><div class="line">        length++;</div><div class="line">        <span class="keyword">if</span>(length==<span class="number">1</span>)A[<span class="number">1</span>]=key;</div><div class="line">        <span class="keyword">else</span></div><div class="line">        &#123;</div><div class="line">            A[length]=key;</div><div class="line">            FilterUp(length);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    </div><div class="line">    <span class="function"><span class="keyword">void</span> <span class="title">FilterUp</span><span class="params">(<span class="keyword">int</span> index)</span></span>&#123;</div><div class="line">        <span class="keyword">if</span>(index ==<span class="number">1</span>)<span class="keyword">return</span> ;</div><div class="line">        <span class="keyword">int</span> parent=index/<span class="number">2</span>;</div><div class="line">        <span class="keyword">if</span>(A[index]&lt;A[parent])</div><div class="line">        &#123;</div><div class="line">            <span class="keyword">int</span> t=A[index]; A[index]=A[parent];A[parent]=t;</div><div class="line">            FilterUp(parent);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    </div><div class="line">    <span class="function"><span class="keyword">void</span> <span class="title">FilterDown</span><span class="params">(<span class="keyword">int</span> index)</span></span>&#123;</div><div class="line">        <span class="keyword">int</span> Left =index+index,Right=Left+<span class="number">1</span>;</div><div class="line">        <span class="keyword">if</span>(Left&gt;length)<span class="keyword">return</span>;</div><div class="line">        <span class="keyword">int</span> minindex;</div><div class="line">        <span class="keyword">if</span>(Right&gt;length)minindex=Left;</div><div class="line">        <span class="keyword">else</span> minindex=(A[Left]&lt;A[Right])? Left:Right;</div><div class="line">        <span class="keyword">if</span>(A[index]&gt;A[minindex])</div><div class="line">        &#123;</div><div class="line">            <span class="keyword">int</span> t=A[index]; A[index]=A[minindex];A[minindex]=t;</div><div class="line">            FilterDown(minindex);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">        MyHeap1 mp=<span class="keyword">new</span> MyHeap1();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h3 id="堆排序"><a href="#堆排序" class="headerlink" title="堆排序"></a>堆排序</h3><h4 id="堆的性质"><a href="#堆的性质" class="headerlink" title="堆的性质"></a>堆的性质</h4><ol>
<li>堆是一棵采用顺序存储结构的完全二叉树；</li>
<li>堆的根结点是关键字序列中的最小(或最大)值，分别称为小(或大)根堆；</li>
<li>从根结点到每一叶子结点路径上的元素组成的序列都是按元素值(或关键字值)非递减(或非递增)的；</li>
<li>堆中的任一子树也是堆。<br>利用堆顶记录的关键字值最小(或最大)的性质，从当前待排序的记录中依次选取关键字最小(或最大)的记录，就可以实现对数据记录的排序，这种排序方法称为堆排序。<h4 id="堆排序思想"><a href="#堆排序思想" class="headerlink" title="堆排序思想"></a>堆排序思想</h4></li>
<li>对一组待排序的记录，按<strong>堆的定义建立堆</strong>；</li>
<li>将<strong>堆顶记录**</strong>和最后一个记录<strong>交换位置，则</strong>前n-1个<strong>记录是</strong>无序<strong>的，而最后一个记录是</strong>有序**的；</li>
<li>堆顶记录被交换后，前n-1个记录不再是堆，需将前n-1个待排序记录重新组织成为一个堆，然后将堆顶记录和倒数第二个记录交换位置，即将整个序列中次小关键字值的记录调整(排除)出无序区；</li>
<li>重复上述步骤，直到全部记录排好序为止。<br><strong>结论</strong>：排序过程中，若采用小根堆，排序后得到的是非递增序列；若采用大根堆，排序后得到的是非递减序列。<h4 id="堆排序的关键"><a href="#堆排序的关键" class="headerlink" title="堆排序的关键"></a>堆排序的关键</h4></li>
<li>如何由一个无序序列建成一个堆？</li>
<li>如何在输出堆顶元素之后，调整剩余元素，使之成为一个新的堆？</li>
</ol>
<p><strong>关键代码</strong><br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">FilterDown</span><span class="params">(<span class="keyword">int</span> index)</span></span>&#123;</div><div class="line">        <span class="keyword">int</span> Left =index+index,Right=Left+<span class="number">1</span>;</div><div class="line">        <span class="keyword">if</span>(Left&gt;length)<span class="keyword">return</span>;</div><div class="line">        <span class="keyword">int</span> minindex;</div><div class="line">        <span class="keyword">if</span>(Right&gt;length)minindex=Left;</div><div class="line">        <span class="keyword">else</span> minindex=(A[Left]&lt;A[Right])? Left:Right;</div><div class="line">        <span class="keyword">if</span>(A[index]&gt;A[minindex])</div><div class="line">        &#123;</div><div class="line">            <span class="keyword">int</span> t=A[index]; A[index]=A[minindex];A[minindex]=t;</div><div class="line">            FilterDown(minindex);</div><div class="line">        &#125;</div><div class="line">    &#125;</div></pre></td></tr></table></figure></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/数据结构/" rel="tag"># 数据结构</a>
          
            <a href="/blog/tags/读书笔记/" rel="tag"># 读书笔记</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/12/26/排序/" rel="next" title="排序">
                <i class="fa fa-chevron-left"></i> 排序
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/12/26/二叉搜索树/" rel="prev" title="二叉搜索树">
                二叉搜索树 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <!--PC版-->
<div id="SOHUCS" ></div>


    

  </div>
     <div class="comments" id="comments">
       
     </div>
   





        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.gif"
               alt="choichumgming" />
          <p class="site-author-name" itemprop="name">choichumgming</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="http://www.weibo.com/u/2558763801" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                    
                      微博
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#堆的定义"><span class="nav-number">1.</span> <span class="nav-text">堆的定义</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#堆的存储结构"><span class="nav-number">1.1.</span> <span class="nav-text">堆的存储结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#堆（Heap）的插入"><span class="nav-number">1.2.</span> <span class="nav-text">堆（Heap）的插入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#堆（Heap）的删除"><span class="nav-number">1.3.</span> <span class="nav-text">堆（Heap）的删除</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#堆排序"><span class="nav-number">1.4.</span> <span class="nav-text">堆排序</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#堆的性质"><span class="nav-number">1.4.1.</span> <span class="nav-text">堆的性质</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#堆排序思想"><span class="nav-number">1.4.2.</span> <span class="nav-text">堆排序思想</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#堆排序的关键"><span class="nav-number">1.4.3.</span> <span class="nav-text">堆排序的关键</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">choichumgming</span>

  
</div>


  <div class="powered-by">
    由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
  </div>

  <span class="post-meta-divider">|</span>

  <div class="theme-info">
    主题 &mdash;
    <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
      NexT.Gemini
    </a>
  </div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cytnT5dky';
      var conf = '56c170b7352bd027682e3707e9eb5071';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  





  





  

  

  

  

  

  

</body>
</html>
